from PyQt5.QtWidgets import QMessageBox

from src.admin.SelectToy_UI import Ui_Form
from PyQt5 import QtWidgets
from src.admin.ToysMsgAlter_win import ToysMsgAlter_Win
from src.admin.AllToys_win import AllToys_Win


class SelectToy_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self,mydb, parent=None):
        super(SelectToy_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        #self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.LoginSignal=False
        self.mydb=mydb

        self.ToysMsg_form=ToysMsgAlter_Win(mydb)
        self.AllToys_form=AllToys_Win(mydb)

        self.ToysMsg_form.setWindowTitle("玩具个体管理")
        self.AllToys_form.setWindowTitle("全部玩具信息")

    def myToysMsg(self):
        s = self.lineEdit.text()
        s = str(s)
        myselect = "SELECT * FROM 玩具个体表 WHERE 玩具编号= " + s
        try:
            mycursor = self.mydb.cursor()
            mycursor.execute(myselect)
        except Exception as a:
            QMessageBox.critical(self, '错误', '信息不正确')
        else:
            result = mycursor.fetchall()
            if len(result) == 0:
                QMessageBox.critical(self, '错误', '请输入正确的玩具编号')
            else:
                self.ToysMsg_form.label_5.setText(str(result[0][0]))
                self.ToysMsg_form.label_6.setText(str(result[0][1]))
                self.ToysMsg_form.label_9.setText(result[0][2])
                self.ToysMsg_form.label_10.setText(result[0][3])
                self.ToysMsg_form.label_12.setText(str(result[0][4]))
                self.ToysMsg_form.label_14.setText(result[0][6])
                self.ToysMsg_form.show()


    def myAllToys(self):
        self.AllToys_form.myTable_init()
        self.AllToys_form.show()
    def getMydb(self,mydb):
        self.mydb=mydb
        self.ToysMsg_form.getmydb(mydb)
        self.AllToys_form.getmydb(mydb)

    def myOut(self):
        self.hide()
